/*
 *  ASequence.cpp
 *  libavid
 *
 *  Created by Peter on 24.02.12.
 *  Copyright 2012 __MyCompanyName__. All rights reserved.
 *
 */

#include "ASequence.h"
#include "AStream.h"

A_IMPLEMENT_CLASS( 'SEQU', ASequence, AComponent );

void ASequence::readFromStream( AStream& str, const AObjDoc& objd )
{
	AComponent::readFromStream( str, objd );
	
	UInt8 tagMark, version;
	str.readPod( tagMark );
	str.readPod( version );
	TR_ASSERT( tagMark == 0x02 );
	TR_ASSERT( version == 0x03 );
	
	Int32 numSubComps;
	str.readPod( numSubComps );
	TR_ASSERT( numSubComps >= 0 );
	
	for( int i = 0; i < numSubComps; ++i )
	{
		UInt32 sequence; // Probably resolvable to an AComposition pointer
		str.readPod( sequence );
		_subComps.push_back( sequence );
	}
	
	str.readPod( tagMark );
	TR_ASSERT( tagMark == 0x03 );
}

void ASequence::dump( std::ostream& str ) const
{
	str << "ASequence {" << std::endl;
	
	str << "\t";
	AComponent::dump( str );
	
	str << "\t_subComps[ " << _subComps.size() << " ] {" << std::endl;
	
	SubCompList::const_iterator it = _subComps.begin();
	
	for( int i = 0; it != _subComps.end(); ++it, ++i ) {
		str << "\t\t" << *it;
		if( i != _subComps.size() - 1 )
			str << ",";
		str << std::endl;
	}
	
	str << "\t}" << std::endl;
	
	str << "}" << std::endl;
}